function mapChildren (children, func, context) {
    //TODO实现此mapChildren方法
    if (!Array.isArray(children)) children = [children];
    children = flattenArray(children, [], ':');
    // console.log(children)
    let mappedChildren = [];
    children.forEach((item, index) => {
        // console.log(item, 'item');
        let resItem = flattenArray(func(item, index), [], '/', item.key);
        mappedChildren.push(...resItem)
    });
    // return mappedChildren;
    return mappedChildren;
}
/* 
    .0/
    .$+key2+/ .$key2/
    [key4]  .3:$key4/
*/

function flattenArray (arr, res = [], split, key) {
    // console.log(arr, 'arr')
    if (!Array.isArray(arr)) res.push(arr);
    arr.forEach((item, index) => {
        // console.log(item, 'item')
        if (key) {
            if (item.key) item.key = `${key}${split}.$${item.key}`
            else item.key = `${key}${split}.${index}`
        } else {
            if (item.key) item.key = `.$${item.key}`
            else item.key = `.${index}`
        }
        Array.isArray(item) ? flattenArray(item, res, ':', item.key) : res.push(item);
    });
    return res;
}

export {
    mapChildren as map,
};